package cn.hallele.bbts.core.component.io;

import cn.hallele.bbts.core.common.constants.MsgCodeConst;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.io.Serial;
import java.io.Serializable;

/**
 * BBTSHeader
 *
 * @author anle5
 * @since 2023/11/29 星期三 23:42
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class BBTSHeader implements Serializable {
    @Serial
    private static final long serialVersionUID = -5965031349224499130L;

    /**
     * 前端通过该字段判断是否处理成功
     * true 处理成功, false 处理失败
     */
    private boolean success;

    /**
     * 消息码 {@link MsgCodeConst}
     */
    private String msgCode;

    /**
     * 消息描述 语言国际化后的对应msgCode的描述
     */
    private String msgDesc;

    /**
     * 客户端ip
     */
    private String ip;

    /**
     * 客户端设备
     */
    private String accessDevice;

    /**
     * setAccessDeviceIfBlank
     *
     * @param accessDevice accessDevice
     */
    public void setAccessDeviceIfBlank(String accessDevice) {
        if (StringUtils.isBlank(this.accessDevice)) {
            this.accessDevice = accessDevice;
        }
    }

    /**
     * setIpIfBlank
     *
     * @param ip ip
     */
    public void setIpIfBlank(String ip) {
        if (StringUtils.isBlank(this.ip)) {
            this.ip = ip;
        }
    }
}
